#include "stdafx.h"
#include "leudgrid/ToolsPath.h"

namespace LEUD
{
	std::string BinaryPath::path()
	{
		char path[MAX_PATH];
		GetModuleFileName(NULL,path,MAX_PATH);
        char *p = strrchr(path, '\\');
        *p = '\0';
		return path;
	}
	std::string BinaryPath::name()
	{
		char path[MAX_PATH];
		GetModuleFileName(NULL,path,MAX_PATH);
        char *p = strrchr(path, '\\');
		return ++p;
	}
	std::string BinaryPath::full()
	{
		char path[MAX_PATH];
		GetModuleFileName(NULL,path,MAX_PATH);
		return path;
	}
	BinaryPathAsCurrentPath::BinaryPathAsCurrentPath(bool reset)
	{
		m_reset = reset;
		char path[MAX_PATH];
		GetCurrentDirectory(MAX_PATH,path);
		m_OldPath = path;
		SetCurrentDirectory( BinaryPath::path().c_str() );
	}
	BinaryPathAsCurrentPath::~BinaryPathAsCurrentPath()
	{
		if( m_reset )
		{
			SetCurrentDirectory(m_OldPath.c_str());
		}
	}
}